package com.lik888.web1.entity.nums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import org.apache.coyote.BadRequestException;


@Getter
public enum Status {
    NORMAL(1, "正在售卖"),
    FROZEN(0, "已下架"),
    UP(2,"上架中");
    @EnumValue
    private final Integer code;
    @JsonValue
    private final String info;
    Status(Integer code, String info) {
        this.code = code;
        this.info = info;
    }
    public static Status of(int value) throws BadRequestException {
        if (value == 0) {
            return FROZEN;
        }
        if (value == 1) {
            return NORMAL;
        }
        if(value ==2)
        {
            return UP;
        }
        throw new BadRequestException("商品状态错误");
    }
}
